package com.boyiis.sell.handler;

import com.boyiis.sell.exception.SellException;
import com.boyiis.sell.exception.SellerAuthorizeException;
import com.boyiis.sell.model.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class SellExceptionHandler {

    //拦截登录异常
    @ExceptionHandler(value = SellerAuthorizeException.class)
    public ModelAndView handlerAuthorizeException(){
        return new ModelAndView("redirect:http:login");
    }


    @ExceptionHandler(value = SellException.class)
    @ResponseBody
    public Result handlerSellException(SellException e){
        Result result = new Result();
        result.setCode(e.getCode());
        result.setMsg(e.getMessage());
        return result;
    }
}
